// 无需权限的固定路由
export const staticRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: { hidden: true }
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '/front',
    hidden: true,
    component: () => import('@/views/frontView/index.vue'),
    redirect: '/front/search', // 添加默认重定向
    children: [
      {
        path: '', // 空路径表示默认子路由
        name: 'FrontHome',
        children: [
          {
            path: 'search',
            name: 'Search',
            meta: { title: '搜索' },
            component: () => import('@/views/frontView/search/index.vue')
          },
          {
            path: 'detail',
            name: 'Detail',
            meta: { title: '详情' },
            component: () => import('@/views/frontView/details/index.vue')
          },
          {
            path: 'profile',
            name: 'Profile',
            meta: { title: '个人中心' },
            component: () => import('@/views/frontView/profile/index.vue')
          }
        ]
      }
    ]
  },
  // 404页面必须最后注册
  { path: '/:pathMatch(.*)*', redirect: '/404', hidden: true }
]

// 布局路由配置
export const layoutRoute = {
  path: '/', // 父级路由路径
  name: 'layoutRoute',  // 新增布局路由名称
  component: () => import('@/layouts/index.vue'),
  redirect: '/dashboard', // 重定向到dashboard页面
  children: [
    // 子路由配置放在这里
  ]
}

// 权限路由配置
export const authRoutes = [
  {
    path: '/dashboard', // 注意这里添加了斜杠
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index.vue'),
    meta: {
      title: '控制台', icon: 'dashboard', affix: true, requiresAuth: true
    },
  },
  {
    path: 'book',
    name: 'Book',
    meta: { title: '图书管理', icon: 'book' },
    children: [
      {
        path: 'list',
        name: 'BookList',
        component: () => import('@/views/dashboard/books/list/index.vue'),
        meta: { title: '图书列表' }
      },
      {
        path: 'tags',
        name: 'BookTags',
        component: () => import('@/views/dashboard/books/tags/index.vue'),
        meta: { title: '标签管理' }
      },
    ]
  },
  {
    path: 'borrow',
    name: 'BookBorrow',
    component: () => import('@/views/dashboard/books/borrow/index.vue'),
    meta: { title: '借阅管理' },
    children:[
      {
        path: 'list',
        name: 'BorrowList',
        component: () => import('@/views/dashboard/books/borrow/list/index.vue'),
        meta: { title: '借阅列表' }
      }
    ]
  },
  // 新增系统管理模块
  {
    path: 'system',
    name: 'System',
    meta: { title: '系统管理', icon: 'system' },
    children: [
      {
        path: 'user',
        name: 'SystemUser',
        component: () => import('@/views/dashboard/system/user/index.vue'),
        meta: { title: '用户管理' }
      },
      {
        path: 'role',
        name: 'SystemSetting',
        component: () => import('@/views/dashboard/system/setting/index.vue'),
        meta: { title: '系统设置' }
      }
    ]
  }
]

// 确保路径正确拼接（移除前导斜杠）
authRoutes.forEach(route => {
  route.path = route.path.replace(/^\//, '')
})

// 将authRoutes中的路由添加到layoutRoute的children中
layoutRoute.children = [...authRoutes];